require 'rubygems'
require 'xml/libxml'
require 'family_tree_api/search/result'

module FamilyTreeApi
  module Search
    NS = ['fs:http://api.familysearch.org/familytree/v1','fsapi:http://api.familysearch.org/v1']
    class Base
      attr_accessor :results

      def self.parse(xml)
        search = self.new
        xp = XML::Parser.new() 
        xp.string = xml
        doc = xp.parse
        search.results = doc.find("//fs:searches/fs:search",NS).collect { |r_element| FamilyTreeApi::Search::Result.parse(r_element) }
        search
      end
    end

  end
end